home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / +system+ / tools / gui / bgui.lha / bgui / Examples / Source / MultiSelect.c < prev    next >
C/C++ Source or Header  |  2000-02-27  |  12KB  |  222 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/MultiSelect.c,v 1.1.2.3 1998/12/07 00:14:09 mlemos Exp $
  3.  *
  4.  * MultiSelect.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * $Log: MultiSelect.c,v $
  12.  * Revision 1.1.2.3  1998/12/07 00:14:09  mlemos
  13.  * Made the listview be activated by the key indicated in the added label.
  14.  *
  15.  * Revision 1.1.2.2  1998/03/01 19:45:41  mlemos
  16.  * Fixed the display of empty lines.
  17.  *
  18.  * Revision 1.1.2.1  1998/02/28 17:45:38  mlemos
  19.  * Ian sources
  20.  *
  21.  *
  22.  */
  23.  
  24. /* Execute me to compile with DICE V3.0
  25. dcc MultiSelect.c -proto -mi -ms -mRR -lbgui
  26. quit
  27. */
  28.  
  29. #include "DemoCode.h"
  30.  
  31. /*
  32. **      The entries shown in the list.
  33. **/
  34. UBYTE   *ListEntries[] = {
  35.         ISEQ_C "This listview object has multi-",
  36.         ISEQ_C "selection turned on. You can",
  37.         ISEQ_C "multi-select the items by holding",
  38.         ISEQ_C "down the SHIFT-key while clicking",
  39.         ISEQ_C "on the different items or by clicking",
  40.         ISEQ_C "on an entry and dragging the mouse",
  41.         ISEQ_C "up or down.",
  42.         "",
  43.         ISEQ_C "If you check the \"No SHIFT\" checbox",
  44.         ISEQ_C "you can multi-select the items without",
  45.         ISEQ_C "using the SHIFT key",
  46.         NULL
  47. };
  48.  
  49. /*
  50. **      Map-list.
  51. **/
  52. struct TagItem CheckToList[] = { GA_Selected, LISTV_MultiSelectNoShift, TAG_END };
  53.  
  54. /*
  55. **      Object ID's.
  56. **/
  57. #define ID_SHOW                 1
  58. #define ID_QUIT                 2
  59. #define ID_ALL                  3
  60. #define ID_NONE                 4
  61.  
  62. VOID StartDemo( void )
  63. {
  64.         struct Window           *window;
  65.         Object                  *WO_Window, *GO_Quit, *GO_Show, *GO_List, *GO_Shift, *GO_All, *GO_None;
  66.         ULONG                    signal, rc, tmp = 0;
  67.         BOOL                     running = TRUE;
  68.  
  69.         /*
  70.          *      Create the window object.
  71.          */
  72.         WO_Window = WindowObject,
  73.                 WINDOW_Title,           "Multi-Selection Demo",
  74.                 WINDOW_AutoAspect,      TRUE,
  75.                 WINDOW_SmartRefresh,    TRUE,
  76.                 WINDOW_RMBTrap,         TRUE,
  77.                 WINDOW_ScaleWidth,      30,
  78.                 WINDOW_ScaleHeight,     30,
  79.                 WINDOW_MasterGroup,
  80.                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  81.                                 StartMember,
  82.                                         VGroupObject, HOffset( 4 ), VOffset( 4 ),
  83.                                                 FRM_Type,               FRTYPE_BUTTON,
  84.                                                 FRM_Recessed,           TRUE,
  85.                                                 StartMember,
  86.                                                         GO_List = ListviewObject,
  87.                                                                 LISTV_EntryArray,               ListEntries,
  88.                                                                 LISTV_MultiSelect,              TRUE,
  89.                                                                 Label("Se_lect next entry"),
  90.                                                                 Place(PLACE_ABOVE),
  91.                                                         EndObject,
  92.                                                 EndMember,
  93.                                                 StartMember,
  94.                                                         HGroupObject,
  95.                                                                 StartMember, GO_All  = KeyButton( "_All",  ID_ALL  ), EndMember,
  96.                                                                 StartMember, GO_None = KeyButton( "N_one", ID_NONE ), EndMember,
  97.                                                         EndObject, FixMinHeight,
  98.                                                 EndMember,
  99.                                         EndObject,
  100.                                 EndMember,
  101.                                 StartMember,
  102.                                         HGroupObject, HOffset( 4 ), VOffset( 4 ),
  103.                                                 FRM_Type,               FRTYPE_BUTTON,
  104.                                                 FRM_Recessed,           TRUE,
  105.                                                 VarSpace( DEFAULT_WEIGHT ),
  106.                                                 StartMember, GO_Shift = KeyCheckBox( "_No SHIFT:", FALSE, 0 ), EndMember,
  107.                                                 VarSpace( DEFAULT_WEIGHT ),
  108.                                         EndObject, FixMinHeight,
  109.                                 EndMember,
  110.                                 StartMember,
  111.                                         HGroupObject, Spacing( 4 ),
  112.                                                 StartMember, GO_Show = KeyButton( "_Show", ID_SHOW ), EndMember,
  113.                                                 VarSpace( DEFAULT_WEIGHT ),
  114.                                                 StartMember, GO_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
  115.                                         EndObject, FixMinHeight,
  116.                                 EndMember,
  117.                         EndObject,
  118.         EndObject;
  119.  
  120.         /*
  121.         **      Object created OK?
  122.         **/
  123.         if ( WO_Window ) {
  124.                 /*
  125.                 **      Assign the keys to the buttons.
  126.                 **/
  127.                 tmp += GadgetKey( WO_Window, GO_Quit,  "q" );
  128.                 tmp += GadgetKey( WO_Window, GO_Show,  "s" );
  129.                 tmp += GadgetKey( WO_Window, GO_Shift, "n" );
  130.                 tmp += GadgetKey( WO_Window, GO_All,   "a" );
  131.                 tmp += GadgetKey( WO_Window, GO_None,  "o" );
  132.                 tmp += GadgetKey( WO_Window, GO_List,  "l" );
  133.                 /*
  134.                 **      OK?
  135.                 **/
  136.                 if ( tmp == 6 ) {
  137.                         /*
  138.                         **      Add notification.
  139.                         **/
  140.                         if ( AddMap( GO_Shift, GO_List, CheckToList )) {
  141.                                 /*
  142.                                 **      try to open the window.
  143.                                 **/
  144.                                 if ( window = WindowOpen( WO_Window )) {
  145.                                         /*
  146.                                         **      Obtain it's wait mask.
  147.                                         **/
  148.                                         GetAttr( WINDOW_SigMask, WO_Window, &signal );
  149.                                         /*
  150.                                         **      Event loop...
  151.                                         **/
  152.                                         do {
  153.                                                 Wait( signal );
  154.                                                 /*
  155.                                                 **      Handle events.
  156.                                                 **/
  157.                                                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  158.                                                         /*
  159.                                                         **      Evaluate return code.
  160.                                                         **/
  161.                                                         switch ( rc ) {
  162.  
  163.                                                                 case    WMHI_CLOSEWINDOW:
  164.                                                                 case    ID_QUIT:
  165.                                                                         running = FALSE;
  166.                                                                         break;
  167.  
  168.                                                                 case    ID_ALL:
  169.                                                                         SetGadgetAttrs(( struct Gadget * )GO_List, window, NULL, LISTV_SelectMulti, LISTV_Select_All, TAG_END );
  170.                                                                         break;
  171.  
  172.                                                                 case    ID_NONE:
  173.                                                                         SetGadgetAttrs(( struct Gadget * )GO_List, window, NULL, LISTV_DeSelect, ~0, TAG_END );
  174.                                                                         break;
  175.  
  176.                                                                 case    ID_SHOW:
  177.                                                                 {
  178.                                                                         UBYTE           *str;
  179.  
  180.                                                                         /*
  181.                                                                         **      Simply dump all selected entries
  182.                                                                         **      to the console.
  183.                                                                         **/
  184.                                                                         if ( str = ( UBYTE * )FirstSelected( GO_List )) {
  185.                                                                                 do {
  186.                                                                                         STRPTR text=str;
  187.  
  188.                                                                                         if(*text)
  189.                                                                                           text++;
  190.                                                                                         if(*text)
  191.                                                                                           text++;
  192.                                                                                         Tell( "%s\n", text);
  193.                                                                                         str = ( UBYTE * )NextSelected( GO_List, str );
  194.                                                                                 } while ( str );
  195.                                                                         } else
  196.                                                                                 /*
  197.                                                                                 **      Oops. There are no selected
  198.                                                                                 **      entries.
  199.                                                                                 **/
  200.                                                                                 Tell( "No selections made!\n" );
  201.                                                                         break;
  202.                                                                 }
  203.                                                         }
  204.                                                 }
  205.                                         } while ( running );
  206.                                 } else
  207.                                         Tell( "Could not open the window\n" );
  208.                         } else
  209.                                 Tell( "Unable to add notification\n" );
  210.                 } else
  211.                         Tell( "Could not assign gadget keys\n" );
  212.                 /*
  213.                 **      Disposing of the window object will
  214.                 **      also close the window if it is
  215.                 **      already opened and it will dispose of
  216.                 **      all objects attached to it.
  217.                 **/
  218.                 DisposeObject( WO_Window );
  219.         } else
  220.                 Tell( "Could not create the window object\n" );
  221. }
  222.